<?php
/**
*  @page review_config Review Settings
*  
*   These are review configurations which can be used to alter various functions related to review on website.
*   
*   @li <b>Allow guest to review listings</b> - Checking this box will allow guest to write reviews for listings.
*   @li <b>Enable captcha on guest review form</b> -  Checking this box will add a captcha on review add form for guest users.
*   @li <b>Allow comments on reviews</b> - Checking this box will allow registered users to post their comments on reviews.
*   @li <b>Allow guest to write comments on reviews</b> - Checking this box will allow guest users to post their comments on reviews.
*   @li <b>Enable captcha on guest review comment form</b> - Checking this box will add a captcha on comment add form for guest users. 
*   @li <b>Use moderation on comments</b> - Checking this box will send all review comments for admin approval instead of publishing them instantly.
*   @li <b>Stop users from reviewing their own listings</b> - Checking this won't allow users to post a review on listing added by themselves.
*   @li <b>Allow users to modify their reviews</b> - Checking this box will allow users to edit the review added by them.
*   @li <b>Don't allow multiple reviews from one IP address on a listing</b> - Checking this box will restrict multiple reviews on a listing from same IP address.
*   @li <b>Moderate new editor reviews</b> - Checking this box will send reviews added by editors for admin approval instead of publishing them instantly.
*   @li <b>Moderate edited editor reviews</b> - Checking this box will send reviews edited by editors for admin approval instead of publishing them instantly.
*   @li <b>Moderate new user reviews</b> - Checking this box will send reviews added by users for admin approval instead of publishing them instantly.
*   @li <b>Moderate edited user reviews</b> - Checking this box will send reviews edited by users for admin approval instead of publishing them instantly.
*   @li <b>Reviews per page limit</b> - You can set the number of reviews to be displayed per page for pages like- All reviews page, %User reviews page.
*   @li <b>Notify me when new review is added</b> - Checking this box will send an email to admin whenever a new review is added.
*   @li <b>Default View</b> - Table view will display review in a tabular format on website and Blog view will display review in a linear format.

*   
*/

App::import('Model','config.BaseConfig');
class ReviewConfig extends BaseConfig
{
	var $name = 'ReviewConfig';
	var $validate = array(
						'paginate_limit'=>array(
							'rule'=>array('validateLimit'),
							'message'=>'Enter a valid numeric value.'
							)
					);	
	var $cache = true;
	
	var $fieldProperties = array(
							'guest_write_review'=>array(
									'group'=>array('add'),
									'label'=>'Allow guest to review listings',
									'type'=>'checkbox',
									'class'=>'guestWriteReview',
									'onchange'=>'toggleCaptcha("guestWriteReview","reviewCaptcha");'
									),
							'captha_on_guest_review'=>array(
									'label'=>'Enable captcha on guest review form',
									'type'=>'checkbox',
									'group'=>'add',
									'default'=>1,
									'class'=>'reviewCaptcha'
								),
							'allow_comment'=>array(
									'group'=>array('add'),
									'label'=>'Allow comments on reviews',
									'type'=>'checkbox',
									),
							'allow_guest_comment'=>array(
									'group'=>array('add'),
									'label'=>'Allow guest to write comments on reviews',
									'type'=>'checkbox',
									'class'=>'guestCommentReview',
									'onchange'=>'toggleCaptcha("guestCommentReview","reviewCommentCaptcha");'
								),
							'captha_on_review_guest_comment'=>array(
									'label'=>'Enable captcha on guest review comment form',
									'type'=>'checkbox',
									'group'=>'add',
									'default'=>1,
									'class'=>'reviewCommentCaptcha'
								),
							'use_moderation_on_comment'=>array(
									'group'=>array('add'),
									'label'=>'Use moderation on comments',
									'type'=>'checkbox',									
									),
							'stop_review_on_own_listing'=>array(
									'group'=>array('add'),
									'label'=>'Stop users from reviewing their own listings',
									'type'=>'checkbox',
									'default'=>'1'
									),
							'allow_review_edit'=>array(
									'label'=>'Allow users to modify their reviews',
									'type'=>'checkbox',
									'group'=>array('add'),
									'default'=>'1'
									),
							'check_ip_addresses'=>array(
									'label'=>'Don\'t allow multiple reviews from one IP address on a listing',
									'type'=>'checkbox',
									'group'=>array('add'),									
									),
							'moderate_new_editor_reviews'=>array(
									'label'=>'Moderate new editor reviews',
									'type'=>'checkbox',
									'group'=>array('add'),
									'default'=>1
									),
							'moderate_edited_editor_reviews'=>array(
									'label'=>'Moderate edited editor reviews',
									'type'=>'checkbox',
									'group'=>array('add'),
									'default'=>1
									),									
							'moderate_new_user_reviews'=>array(
									'label'=>'Moderate new user reviews',
									'group'=>array('add'),
									'type'=>'checkbox',
									'default'=>'1'
									),
							'moderate_edited_user_reviews'=>array(
									'label'=>'Moderate edited user reviews',
									'type'=>'checkbox',
									'group'=>array('add'),
									'default'=>1
									),	
							'paginate_limit'=>array(
									'label'=>'Reviews per page limit (max. limit 100)',
									'type'=>'text',
									'class'=>'vsmall_input',
									'group'=>array('add'),
									'default'=>10									
									),	
							'enable_add_review_admin_alert'=>array(
									'label'=>'Notify me when new review is added',
									'group'=>array('add'),
									'type'=>'checkbox',
									'default'=>1									
									),
							'view_type'=>array(
									'label'=>'Default View',
									'type'=>'radio',
									'options'=>array(
											'table_view'=>'Tableview',
											'blog_view'=>'Blogview'
											),
									'default'=>'blog_view',
									'group'=>array('add'),
									),
								'upload_assets' => array(
										'label'=>"Users can upload images with reviews",
										'group'=>array('add'),
										'type'=>'checkbox',
										'default'=>1
								),
							);
							
	function validateLimit($data)
	{
		$return = true;
		if(empty($data['paginate_limit']))
		{
			$return = false;
		}
		if(count(explode('.',$data['paginate_limit'])) > 1)
		{
			$return = false;
		}
		if(is_numeric($data['paginate_limit']) == false)
		{
			$return = false;	
		}elseif($data['paginate_limit'] > 100)
		{
			$return = false;
		}
		
		return $return;
	}
    
    function init()
    {
      parent::init();
      if(!cr("ListingConfig"))
      {
        cri("ListingConfig")->init();
      }
      //Allow user to review on their added listing if review on listing add is allowed.
      if(cr("ReviewConfig.stop_review_on_own_listing"))
      {
			Configure::write("ListingConfig.add_review_with_listing",0);
      }
    }

}
?>